package com.finance.client;

import com.finance.util.CommonUtil;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

@Component
public class ApiCallService {

    private final RestTemplate restTemplate;

    public ApiCallService(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    public String callApi(String urlHead, String urlPath, Map<String, String> params) {
        String url = urlHead + urlPath;
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<Map<String, String>> request = new HttpEntity<>(params, headers);
        return restTemplate.postForObject(url, request, String.class);
    }
} 